import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login'
Vue.use(VueRouter)

const routes = [
    { path: '/', redirect: '/login' },
    { path: '/login', component: Login },
    {
        path: '/home',
        component: () =>
            import ('../components/Home')
    }
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})
router.beforeEach((to, from, next) => {
    if (to.path == '/login') return next()
    const username = sessionStorage.getItem('username')
    const password = sessionStorage.getItem('password')
    if (!username || !password) return next('/login')
    next()
})
export default router